package com.spring.boot.reponse;


//import com.google.gson.Gson;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 接口返回基础类
 * Created by nayunhao on 2021/01/01.
 */
public class ResponseJson {
    private Object data = null;
    
    /**
     * SUCCESS/ERROR
     */
    private String Result;
    
    /**
     * 响应代码
     */
    private String Code;

    /**
     * 响应消息
     */
    private String Message;



    public ResponseJson() {
    	this.Result = "";
        this.Code = "";
        this.Message = "";
    }

    /**
     * 接口返回信息设定
     * @param errorInfo
     */
    public ResponseJson(ErrorInfoInterface errorInfo) {
    	this.Result = errorInfo.getResult();
        this.Code = errorInfo.getCode();
        this.Message = errorInfo.getMessage();

    }

    /**
     * 接口返回信息设定
     * @param errorInfo
     * @param strField 错误信息参数
     */
    public ResponseJson(ErrorInfoInterface errorInfo, String strField) {
    	this.Result = errorInfo.getResult();
        this.Code = errorInfo.getCode();

        this.Message = String.format(errorInfo.getMessage(),strField);
    }

    /**
     * 
     * @param errorInfo
     * @param strField1
     * @param strField2
     * @author nayunhao
     */
    public ResponseJson(ErrorInfoInterface errorInfo, String strField1, String strField2) {
    	this.Result = errorInfo.getResult();
        this.Code = errorInfo.getCode();
        this.Message = String.format(errorInfo.getMessage(),strField1,strField2);
    }
    
    /**
     * @Author nayunhao
     * @Description 错误集合用,分割返回
     * @Date 2019/7/3 19:43
     * @param errorInfo
     * @param strFieldList
     * @return
     **/
    public ResponseJson(ErrorInfoInterface errorInfo, List<String> strFieldList) {
        this.Result = errorInfo.getResult();
        this.Code = errorInfo.getCode();

        if(!StringUtils.isEmpty(strFieldList)){
            this.Message = String.format(errorInfo.getMessage() ,String.join(",",strFieldList));
        }else{
            this.Message = errorInfo.getMessage();
        }
    }
    
    public String getResult() {
		return Result;
	}

	public void setResult(String result) {
		Result = result;
	}

	public String getCode() {
        return Code;
    }

    public void setCode(String Code) {
        this.Code = Code;
    }

    public String getMessage() {
        return Message;
    }

    public void setMessage(String Message) {
        this.Message = Message;
    }
    
    public void addData(Object data) {
    	this.data = data;
    }
    
    public Object getData() {
		return data;
	}

//	public String toString() {
//    	Map<String, Object> j = new LinkedHashMap<String, Object>();
//    	j.put("Result", Result);
//        j.put("Code", Code);
//        j.put("Message", Message);
//        j.put("data", data);
//        return new Gson().toJson(j);
//    }

}